from django.shortcuts import render
from .models import Metal
# Create your views here.


def index(request):
    """generate index"""
    return render(request, "metal_plan/index.html")


def metals(request):
    """Show all metal"""
    metals = Metal.objects.order_by("date_added")
    context = {"metals": metals}
    return render(request, "metal_plan/metals.html", context)


def metal(request, metals_id):
    """Show a single metal and all its detail"""
    metals = Metal.objects.get(id=metals_id)
    metal = metals.detail_set.order_by('-date_added')
    context = {'metals': metals, 'metal': metal}
    return render(request, "metal_plan/metal.html", context)